import Cookies from 'js-cookie'

const layout = {
  state: {
    theme: Cookies.get('theme') || 'blue',
    sidebarFolded: +Cookies.get('sidebarFolded')
  },
  getters: {
    sidebarFolded: state => !!state.sidebarFolded,
    theme: state => state.theme
  },
  mutations: {
    toggleSidebar: state => {
      state.sidebarFolded = !state.sidebarFolded
      Cookies.set('sidebarFolded', state.sidebarFolded ? 1 : 0)
    },
    changeTheme: (state, theme) => {
      state.theme = theme
      Cookies.set('theme', theme)
    }
  },
  actions: {
    toggleSidebar: ({ commit }) => {
      commit('toggleSidebar')
    },
    changeTheme: ({ commit }, theme) => {
      commit('changeTheme', theme)
    }
  }
}

export default layout
